<div class="page-header">
	<h1>
		修改密码
	</h1>
</div><!-- /.page-header -->

<div class="row">
	<div class="col-md-offset-1 col-md-6">
		<div class="alert alert-danger">
			<span>提示：</span><span id="err_info">新密码必须包含数字和字母，8到16位</span>
		</div>
	</div>

	<div class="col-xs-12">
		<form class="form-horizontal" role="form" id="change_pwd_form">
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 用户名 </label>

				<div class="col-sm-9">
					<input type="text" id="form-field-1" value="{{ username }}" class="col-xs-10 col-sm-5" disabled/>
				</div>
			</div>

			<div class="space-4"></div>

			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-2"> 原密码 </label>

				<div class="col-sm-9">
					<input type="password" id="form-field-2" name="old_password" placeholder="请输入原密码" class="col-xs-10 col-sm-5"/>
					{#					<span class="help-inline col-xs-12 col-sm-7">#}
					{#						<span class="middle">Inline help text</span>#}
					{#					</span>#}
				</div>
			</div>

			<div class="space-4"></div>

			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-3"> 新密码 </label>

				<div class="col-sm-9">
					<input type="password" id="form-field-3" name="new_password" placeholder="请输入新密码" class="col-xs-10 col-sm-5"/>
					{#					<span class="help-inline col-xs-12 col-sm-7">#}
					{#						<span class="middle">Inline help text</span>#}
					{#					</span>#}
				</div>
			</div>

			<div class="space-4"></div>

			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-4"> 重新输入新密码 </label>

				<div class="col-sm-9">
					<input type="password" id="form-field-4" name="re_new_password" placeholder="请重新输入新密码" class="col-xs-10 col-sm-5"/>
					{#					<span class="help-inline col-xs-12 col-sm-7">#}
					{#						<span class="middle">Inline help text</span>#}
					{#					</span>#}
				</div>
			</div>

			<div class="col-md-offset-3 col-md-9">
				<button class="btn btn-info" type="button" onclick="request_change_pwd()">
					<i class="ace-icon fa fa-check bigger-110"></i>
					修改
				</button>
			</div>

		</form>

	</div>
</div>

<script>

	function request_change_pwd() {
		var data = formserializeJson("change_pwd_form");

		function callback(data, status, xhr) {
			if (status == "success") {
				$('#err_info').empty();
				$('#err_info').html(data.reason);
				if (data.c == 0) {
					$("#err_info").html(data.m);
					//setCookie("session_id", data.session_id);
					{# window.location.href = data.login_url;#}

					$("#form-field-2").val("");
					$("#form-field-3").val("");
					$("#form-field-4").val("");
				} else {
					$("#err_info").html(data.m);
					//resetValidateCode()
				}
			} else {
				// resetValidateCode()
				$("#err_info").html("错误信息: <br/>" + xhr.status + " " + xhr.statusText)
			}
		}

		$("#err_info").html("正在提交...");
		var url = "/smAdmin/api/change_pwd";
		$.post(url, data, callback, 'json');
	}
</script>